#!/bin/gawk -f

# Convert a .txt file from the doc directory to HTML format

NR == 1 {
    tit = $2
    sub( /\.txt\./, "", tit )
    toupper( tit )
    toplin = $3
    for ( i=4; i<=NF; i++ )
	toplin = toplin " " $i
    print "<HTML>"
    print "<HEAD>"
    print "<TITLE>" tit "</TITLE>"
    print "</HEAD>\n"
    print "<BODY>"
    print "<H1>" tit "</H1>"
    print "<H3>" toplin "</H3>"
    print "<P><HR><P>\n"
    next
}

NF == 0 {
    print "\n<P>\n"
    next
}

/^-*$/ {
    next
}

/^[-_. A-Z0-9]*$/ {
    print "\n<H2>" $0 "</H2>"
    next
}

/'qhelp/ {
    match( $0, /'qhelp [^']*'/ )
    topic = substr( $0, RSTART+7, RLENGTH-8 )
    ref = "<A HREF=\""topic".html\">"topic"</A>"
    sub( /'qhelp [^']*'/, ref )
}

/'/ {
    for ( i=1; i<=NF; i++ ) {
	if ( $i ~ /'.*'/ ) {
	    sub( /'/, "<B>", $i )
	    sub( /'/, "</B>", $i )
	}
    }
}

/^ *[0-9]\./ {
    sub( /^ *[0-9]\./, "" )
    print "<LI>"$0
    next
}

    {
    print $0
}

END {
    print "</BODY>"
    print "</HTML>"
}
